home *** CD-ROM | disk | FTP | other *** search
/ PC Open 97 / PC Open 97 CD2.bin / Demo / FileMaker / FileMaker Pro Prova / Files / Data1.cab / fixed_width.xsl4 < prev    next >
Encoding:
Extensible Markup Language  |  2002-05-24  |  4.7 KB  |  132 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult">
  3.     <xsl:output method="text"  version="1.0" encoding="UTF-8" indent="no"/>
  4. <!--
  5. File: fixed_width.xsl
  6.  
  7. Transforms data exported in the FMPXMLRESULT grammar into a stream
  8. of data with fixed column widths. Fields shorter than the set width
  9. are padded with defined characters. The default behavior is to pad 
  10. with spaces, but this may be changed in the variable 'padding_character'
  11. below. Data in any field exceeding the length defined in the variable
  12. 'columnwidth' will be truncated (removed) from the final output. Note
  13. that there are no delimiters between outputted fields, the data runs
  14. together in one continuous stream for each record.
  15.  
  16. For example, a database such as this:
  17.  
  18. Field A           Field B     Field C
  19. Data in field A   One         Another
  20. The               Next        Again
  21. 11                32          FileMaker
  22.  
  23. when exported with a 'columnwidth' of four (4) will appear
  24. like this:
  25.  
  26. ============
  27. DataOne Anot
  28. The NextAgai
  29. 11  32  File
  30.  
  31. Change the value of the variable "columnwidth" below to adjust
  32. column width.
  33.  
  34. Note that the function substring(string, start, length) is one 
  35. based, not zero based.
  36.  
  37. ===============================================================
  38.  
  39. Copyright ┬⌐ 2002 FileMaker, Inc.
  40. All rights reserved.
  41.  
  42. Redistribution and use in source and binary forms, with or
  43. without modification, are permitted provided that the following
  44. conditions are met:
  45.  
  46. * Redistributions of source code must retain the above copyright
  47.   notice, this list of conditions and the following disclaimer.
  48.  
  49. * Redistributions in binary form must reproduce the above copyright
  50.   notice, this list of conditions and the following disclaimer in 
  51.   the documentation and/or other materials provided with the
  52.   distribution.
  53.  
  54. * Neither the name of the FileMaker, Inc. nor the names of its 
  55.   contributors may be used to endorse or promote products derived
  56.   from this software without specific prior written
  57.   permission.
  58.  
  59. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  60. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  61. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  62. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
  63. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
  64. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  65. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  66. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  67. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  68. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  69. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  70. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  71.     
  72. ===============================================================
  73. -->
  74.     <xsl:template match="fmp:FMPXMLRESULT">
  75.         <xsl:for-each select="fmp:RESULTSET/fmp:ROW">
  76.             <xsl:for-each select="fmp:COL">
  77.                 <xsl:choose>
  78.                     <xsl:when test="string-length(fmp:DATA) < $columnwidth">
  79.                         <xsl:value-of select="fmp:DATA"/>
  80.                         <xsl:call-template name="pad_output">
  81.                             <xsl:with-param name="numspaces" select="$columnwidth - string-length(fmp:DATA)"/>
  82.                         </xsl:call-template>
  83.                     </xsl:when>
  84.                     <xsl:otherwise>
  85.                         <xsl:value-of select="substring(fmp:DATA,1,$columnwidth)"/>
  86.                     </xsl:otherwise>
  87.                 </xsl:choose>
  88.             </xsl:for-each>
  89.             <xsl:value-of select="$newline"/>
  90.         </xsl:for-each>
  91.     </xsl:template>
  92.     
  93. <!--
  94. Template: pad_output
  95.     
  96. Recursive function that accepts a parameter of number of padding
  97. characters to output.
  98. -->
  99.     <xsl:template name="pad_output">
  100.         <xsl:param name="numspaces" select="0"/>
  101.         <xsl:if test="$numspaces > 0">
  102.             <xsl:value-of select="$padding_character"/>
  103.             <xsl:call-template name="pad_output">
  104.                 <xsl:with-param name="numspaces" select="$numspaces - 1"/>
  105.             </xsl:call-template>
  106.         </xsl:if>
  107.     </xsl:template>
  108.     
  109. <!--
  110. This variable controls the uniform column width of every field.
  111. -->
  112.     <xsl:variable name="columnwidth">
  113.         <xsl:text>17</xsl:text>
  114.     </xsl:variable>
  115. <!--
  116. The default is to pad fields shorter than "columnwidth" with spaces
  117. but this can be changed to any character.
  118. -->
  119.     <xsl:variable name="padding_character">
  120.         <xsl:text> </xsl:text>
  121.     </xsl:variable>
  122. <!--
  123. The output method of "text" will handle the carriage return between the
  124. xsl:text tags below. This may also be changed to any character and is
  125. especially useful when the output is to be machine "read".
  126. -->    
  127. <xsl:variable name="newline">
  128. <xsl:text>
  129. </xsl:text>
  130. </xsl:variable>
  131. </xsl:stylesheet>
  132.